<?php

/**
 * 设置任务进度
 * @param unknown $user_id 用户id
 * @param unknown $task_nav_id  任务栏目id
 */
function setFinish($user_id,$task_nav_id){
    $finish_count= M('finish_count')->where(array('user_id'=>$user_id,'task_nav_id'=>$task_nav_id))->find();
    if (empty($finish_count)){
        $finish_count= array(
            'user_id' =>$user_id,
            'task_nav_id' => $task_nav_id,
            'finish' => 1,
        );
        M('finish_count')->add($finish_count);
    }else{
        M('finish_count')->where(array('user_id'=>$user_id,'task_nav_id'=>$task_nav_id))->setInc('finish');
    }
}

/**
 * 记录用户日志
 * @param unknown $user_id 用户id
 * @param unknown $charge_type  用户充值类型 
 * @param unknown $cherge_desc  充值类型描述
 * @param unknown $type  1 金钱   2 积分
 * @param number $money      金钱使用跟充值数目，正数代表充值，负数代表使用
 * @param number $point      积分使用跟充值数目，正数代表充值，负数代表使用
 */
function setUserLog($user_id,$charge_type,$cherge_desc,$type,$money=0,$point=0){
    $charge_log = array(
        'user_id' => $user_id,
        'charge_type' => $charge_type,
        'charge_desc' => $cherge_desc,
        'money' => $money,
        'point' => $point,
        'type' => $type
    );
    $user_id = session('user.id');
    $res = M('user_log')->add($charge_log);
    
    if ($res !== false){
        if ($type == 1){
            $res = M('user')->where(array('id'=>$user_id))->setInc('money',$money);
            
        }else {
            $res = M('user')->where(array('id'=>$user_id))->setInc('point',$point);
            
        }
        if ($res !== false){
            return true;
        }else{
            return false;
        }
    }else {
        return false;
    }
}




